<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>确认订单</title>
		<!-- 引入样式 -->
		<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/vant@beta/lib/index.css">
		<!-- 引入组件 -->
		<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.min.js"></script>
		<script src="https://cdn.jsdelivr.net/npm/vant@beta/lib/vant.min.js"></script>
		<script type="application/javascript" src="../js/flexible.debug.js"></script>
		<script type="application/javascript" src="../js/flexible_css.debug.js"></script>
		<script type="text/javascript" src="../js/jquery-1.10.1.min.js"></script>
		<script type="text/javascript" src="../js/querystring.min.js"></script>
		<script type="text/javascript" src="../js/cfg.js"></script>
		<script src="http://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>
		<link rel="stylesheet" href="../css/layout.css">
	</head>
	<body>
		<div id="app" v-cloak>
			<div class="top backgroundcolorfff content" @click="goaddress()">
				<p class="font30 color333 rightIcon height30" v-if="defaultAddress">
					<em class="moren mg-r12" v-if="defaultAddress.ad_status=='0'"></em>
					<em class="icon position width24 height30 mg-r12" v-else-if="defaultAddress.ad_status!='0'"></em>
					<span class="width582 buhuanhang displayInline lineheight30">{{defaultAddress.ad_province}}{{defaultAddress.ad_city}}{{defaultAddress.ad_detail_address}}</span></p>
				<p class="font30 color333 rightIcon height30 lineheight30" v-else-if="defaultAddress==''"><em class="icon position width24 height30 mg-r12"></em>请添加收货地址</p>
			</div>
			<div class="midell mg-t20 backgroundcolorfff content">
				<div class="displayFlex">
					<p class="left flex1 color333 font28"><em class="icon"><img src="../img/logo.png" alt="logo" class="mg-r12"></em>一城一盒
						重庆特产</p>
					<p class="right"><img src="../img/kuaidi.png" alt="快递" class="width114 height30"></p>
				</div>
				<div class="displayFlex mg-t32">
					<div class="width162 height162"><img src="../img/logo.png" alt="" class="width100p height100p"></div>
					<div class="mg-l43">
						<p class="font26 color333 lineHeight40 letterSpacing1">最具重庆特色礼盒，包括茶、饮、食、佐、料、小吃、火锅、餐具等。</p>
						<p class="mg-t30 displayFlex">
							<span class="colorf72929 font36 left flex1">¥
								<em v-if='orderType==0'>{{cost.og_present_price|formatFixed}}</em>
								<em v-else-if='orderType==1'>{{cost.og_assemble_price|formatFixed}}</em>
							</span>
							<span class="right">
								<van-stepper v-model="orderNumber" @change="changeorder" /></span>
						</p>
					</div>
				</div>
			</div>
			<div class="bottom height82 displayFlex lineheight82 width100">
				<p class="backgroundcolorfff flex2 textCenter">
					<span class="color333 font26">实付金额:</span>
					<span class="font34 fontBold colorf72929"><em>¥</em>{{total|formatFixed}}<em class="font26 letterSpacing1">(免运费)</em></span>
				</p>
				<p class="backgroundcolorf72929 flex1 font30 colorfff textCenter" @click="goPay">立即支付</p>
			</div>
		</div>
		<script>
			var vant = window.vant;
			var qsd = querystring.parse();
			var cfg = new AppCfg().init({
				isDebug: false,
			});
			Vue.use(vant);
			var myapp=new Vue({
				el: '#app',
				data: {
					orderNumber: 1,
					value: 1,
					cost: '',
					total: '',
					defaultAddress: '',
					addressId: '',
					orderType: qsd.orderType?qsd.orderType:'',
					parentNo:qsd.parent_order_no?qsd.parent_order_no:''
				},
				created: function() {
					this.checkaddress();
					this.setPrice();
				},
				methods: {
					// 价格设置
					setPrice: function() {
						var that = this;
						cfg.majaxAction("queryOriginaDetail", '', function(res) { //价格设置
							if (res.data) {
								that.cost = res.data; //true拼团已满提示语,false平图案未满直接拼团购
								that.total = (qsd.orderType == 0 ? that.cost.og_present_price : that.cost.og_assemble_price)
							}
						});
					},
					checkaddress: function() {
						var that = this;
						cfg.majaxAction("queryAddressInfoList", '', function(res) {
							if (res.data.length > 0) {
								for (var i = 0; i < res.data.length; i++) {
									if (res.data[i].id == qsd.addressid) {
										that.defaultAddress = res.data[i];
										that.addressId = res.data[i].id;
									} else if (res.data[i].ad_status == 0) {
										that.defaultAddress = res.data[i];
										that.addressId = res.data[i].id;
									}
								}
							} else {
								that.defaultAddress = "";
							}
						});
					},
					goaddress: function() {
						window.location.href = "address.html?orderType=" + qsd.orderType;
					},
					changeorder(value) {
						this.orderNumber = value;
						this.total = value * (this.orderType == 0 ? this.cost.og_present_price : this.cost.og_assemble_price);
					},
					goPay:function(val){
						var that = this;
						var parm = {
							id: '',
							order_number: that.orderNumber, //数量
							order_price: that.orderType == 0 ? that.cost.og_present_price : that.cost.og_assemble_price, //单价
							address_id: that.addressId, //收货地址ID
							order_amount: that.total, //金额
							product_id: '1', //产品编号
							order_type: that.orderType, //订单类型(0:个人订单,1:拼团订单)
							order_status: '0', //订单状态(0:待付款,1:待发货,2:待收货,3:待评价,4:交易完成,5:已取消)
							parent_order_no: '', //拼团发起订单编号
							user_id: that.userid
						}
						cfg.majaxAction("saveOrUpdateOrder", parm, function(res) {
							if (res.data) {
								window.location.href = "pay.html?orderno=" + res.data+"&amount="+that.total+'&ordertype='+that.orderType;
							}
						})
					},
				},
				filters: {
					formatFixed: function(val) {
						return parseFloat(val).toFixed(2)
					}
				}
			})
		</script>
	</body>
</html>
